package com.cd.hospital.www.web;

import java.util.List;
import java.util.Map;

import com.cd.hospital.common.utils.PageUtils;
import com.cd.hospital.common.utils.Query;
import com.cd.hospital.common.utils.R;
import com.cd.hospital.modules.entity.PageviewEntity;
import com.cd.hospital.modules.service.PageviewService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;




/**
 * 访问量统计
 * 
 * @author weirdor
 * @email 179946422@qq.com
 * @date 2017-10-11 18:57:04
 */
@RestController
@RequestMapping("/modules/pageview")
public class PageviewController {
	@Autowired
	private PageviewService pageviewService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("modules:pageview:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<PageviewEntity> pageviewList = pageviewService.queryList(query);
		int total = pageviewService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(pageviewList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}


	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("modules:pageview:info")
	public R info(@PathVariable("id") Integer id){
		PageviewEntity pageview = pageviewService.queryObject(id);

		return R.ok().put("pageview", pageview);
	}

	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("modules:pageview:save")
	public R save(@RequestBody PageviewEntity pageview){
		pageviewService.save(pageview);

		return R.ok();
	}

	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("modules:pageview:update")
	public R update(@RequestBody PageviewEntity pageview){
		pageviewService.update(pageview);

		return R.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("modules:pageview:delete")
	public R delete(@RequestBody Integer[] ids){
		pageviewService.deleteBatch(ids);

		return R.ok();
	}

}
